<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/global.jsp" %>

<%-- 填充content --%>
<layout:override name="content">
    <div class="navbar">
        <div class="navbar-inner">
            <a href="${ctxPath}/" class="brand">
                <span class="first">${siteName}</span>
            </a>
        </div>
    </div>
    <div class="row-fluid">
        <div class="dialog">
            <div class="block">
                <p class="block-heading">登录
                    <a href="${ctxPath}/api/osc" title="开源中国快速登录" style="height: 34px;margin-right: 10px;" class="pull-right">
                        <img src="${cdnPath}/static/images/osc_s.png"/>
                    </a>
                    <a href="${ctxPath}/api/qq" title="qq快速登录" style="height: 34px;margin-right: 10px;" class="pull-right">
                        <img src="${cdnPath}/static/images/qq_s.png"/>
                    </a>
                    <a href="${ctxPath}/api/baidu" title="百度帐号登录" style="height: 34px;" class="pull-right">
                        <img src="${cdnPath}/static/images/login-baidu.png"/>
                    </a>
                    <a href="${ctxPath}/api/sina" title="新浪微博登陆" style="height: 34px;margin-right: 10px;" class="pull-right">
                        <img src="${cdnPath}/static/images/sina_b.png"/>
                    </a>
                </p>
                <div class="block-body">
                    <form action="${ctxPath}/admin/session" method="post">
                        <label>邮箱帐号：</label>
                        <input type="email" name="email" required="required" original-title="请输入您的常用邮箱！" class="span12"/>
                        <label>密码：</label>
                        <input type="password" name="pwd" required="required" original-title="请输入您的密码！" class="span12"/>
                        <input type="submit" value="登录" class="btn btn-primary pull-right"/>
                        <label class="remember-me">
                            <input type="checkbox" name="remember" value="1" original-title="有效期一个月！"/>&nbsp;记住密码
                        </label>
                        <div class="clearfix"></div>
                    </form>
                </div>
            </div>
            <p class="pull-right">
                <a href="#" class="forgot">忘了密码？</a>
            </p>
        </div>
    </div>
</layout:override>

<%-- 填充script --%>
<layout:override name="script">
    <script>
        $(function() {
            $('form').submit(function() {
                var dialog = $.dialog();
                _post(this, dialog, function(data) {
                    if (data.success) {
                        dialog.content('登录成功！').lock().time(1000);
                        setTimeout(function() {
                            location.reload();
                        }, 1000);
                    } else {
                        dialog.content(data.msg).lock().time(2000);
                    }
                });
                return false;
            });
            $('.forgot').click(function() {
                var dialog = $.dialog({
                    title : '请输入邮箱地址：',
                    content : '<input id="reset-pwd" name="email" style="width:15em; padding:4px"/>',
                    lock : true,
                    ok : function() {
                        var input = $('#reset-pwd');
                        var email = $.trim(input.val());
                        if (!/^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/.test(email)) {
                            input.select();
                            input.focus();
                            return false;
                        } else {
                            var ajaxDialog = $.dialog({
                                fixed : true,
                                lock : true
                            });
                            $.post("${ctxPath }/reset_pwd", {
                                email : email
                            }, function(data) {
                                if (data.success) {
                                    ajaxDialog.title('邮件发送成功！');
                                    ajaxDialog.content('请登录邮箱按指示完成密码重置操作！').lock().time(2000);
                                } else {
                                    ajaxDialog.title('提示！');
                                    ajaxDialog.content(data.msg).lock().time(2000);
                                }
                            });
                        };
                    },
                    cancel : true
                });
                return false;
            });
        })
    </script>
</layout:override>

<%@ include file="/commons/_layout_admin.jsp" %>